<script>
    $(document).ready(function() {
        $('#taskList').dataTable({
            "sPaginationType": "full_numbers",
            "aoColumnDefs": [
                {"bSortable": false, "aTargets": [0, 4]}
            ]
        });
        $('#taskList_first').html('<i class="fa fa-fast-backward"></i>');
        $('#taskList_previous').html('<i class="fa fa-backward"></i>');
        $('#taskList_next').html('<i class="fa fa-forward"></i>');
        $('#taskList_last').html('<i class="fa fa-fast-forward"></i>');
    });
</script>
<div class="header" id="header" streamid="<?php echo $this->streamView->model->streamId; ?>" threadid="" messageid="">
    <div class="top-banner">
        <p>
            <span class="menu" id="menu-button">
                <i class="fa fa-bars fa-2x"></i>
            </span>
            <span class="title">TASK MANAGER</span>
            <span class="detail" id="filter-button"><i class="fa fa-bookmark fa-2x"></i></span>
        </p>
    </div>
    <div class="buzz-action task-manager buzz-sms hide" id="send-sms">
        <div class="wrapp">
            <div class="title">
                <p>SEND SMS</p>
                <p style="color: #0086B3; display: none;">Message has send!</p>
            </div>
            <div class="form">
                <input name='sendTo' type="text" placeholder="To">
                <br>
                <textarea name='message'></textarea>
                <button class="submit" dataType="send-sms">Send</button>
                <button class="cancel" dataType="send-sms">Cancel</button>
            </div>				
        </div>		
    </div>
    <div class="buzz-action task-manager buzz-mark-complete hide" id="mark-complete">
        <div class="wrapp">
            <div class="title">
                <p>COMPLETE TASK</p>
            </div>
            <div class="form">
                <p>Action</p>
                <textarea name=""></textarea>
                <div class="help-block">Enter the solution of the task</div>
                <button class="submit" dataType="mark-complete">Save</button>
                <button class="cancel" dataType="mark-complete">Cancel</button>
            </div>				
        </div>		
    </div>
</div>
<div class="content content-thread content-engagement" id="content">
    <div id="tableTopSources_wrapper" class="dataTables_wrapper wrap-block" role="grid">
        <h4>Task Data Table</h4>
        <table id="taskList" class="taskdata">
            <thead hidden>
            <th width="9%">Date</th>
            <th widht="10%">Assigned To</th>
            <th width="19%">Post</th>
            <th width="19%">Action</th>
            <th width="6%">Tags</th>
            <th width="19%">Task Description</th>
            <th width="6%">Done</th>
            </thead>
            <tbody>
                <?php
                if (count($this->taskView->tasks) > 0)
                    foreach ($this->taskView->tasks as $task) :
                        $fullContent = $task->post;
                        ?>
                        <tr taskid="<?php echo $task->taskId; ?>" class="task">
                            <td class="time"><?php echo $task->taskDateCreated->format("d M H:i"); ?></td>
                            <td class="assignedTo"><?php echo $task->assignedTo->name ?></td>
                            <td class="post"><?php echo $fullContent; ?></td>
                            <td class="action"><?php echo $task->action; ?></td>
                            <td class="tags">
                                <?php
                                $tags = $task->tags;
                                for ($i = 0; $i < sizeof($tags); $i++) {
                                    $firstLetter = substr($tags[$i]->tagName, 0, 1);
                                    if ($i > 0) {
                                        echo ', <span class="' . $firstLetter . '" title="' . $tags[$i]->tagName . '">' . $firstLetter . '</span>';
                                    } else {
                                        echo '<span class="' . $firstLetter . '" title="' . $tags[$i]->tagName . '">' . $firstLetter . '</span>';
                                    }
                                }
                                ?>
                                <i class="fa fa-plus"></i>
                            </td>
                            <td class="description"><?php echo $task->taskNote ?></td>						
                            <td class="isdone">
                                <?php
                                switch ($task->taskType) {
                                    case '10':
                                        if ($task->status == 2) {
                                            echo '<i datatype="send-email" class="fa fa-share complete"></i>';
                                        } else {
                                            echo '<i datatype="send-email" class="fa fa-share"></i>';
                                        }
                                        break;
                                    case '11':
                                        if ($task->status == 2) {
                                            echo '<i datatype="send-sms" class="fa fa-comment complete"></i>';
                                        } else {
                                            echo '<i datatype="send-sms" class="fa fa-comment"></i>';
                                        }
                                        break;
                                    default:
                                        if ($task->status == 2)
                                            echo '<i datatype="mark-complete" class="fa fa-check complete"></i>';
                                        else
                                            echo '<i datatype="mark-complete" class="fa fa-check"></i>';
                                }
                                ?>
                            </td>
                        </tr>
                    <?php endforeach; ?>
            </tbody>
        </table>
    </div> <!-- END dataTables_wrapper wrap-block -->
</div> <!-- End Content -->
